import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';
import checkBtnPermission from './checkBtnPermission';

export default function editData() {
    const {tabKey, orgVal, contractArea, agreeArea, contractData, agreeData} = this.state;
    if (tabKey === 'contract') {
        checkBtnPermission(contractData.rows[0].values.pk_psndoc_sub.value, 'edit', 'contract', () => {
            proFetch({
                url: '/nccloud/hrcm/account/EditContractAction.do',
                body: {
                    pk_org: orgVal.refpk,
                    selectedPk: contractData.rows[0].values.pk_psndoc_sub.value,
                    isContract: true
                },
            }).then((res) => {
                if (res.success) {
                    this.props.form.setFormStatus(contractArea, 'edit');
                    /*if (contractData.rows[0].values.hasOwnProperty('ifprop')) {
                        initFormMeta.call(this, 'contract', contractArea, contractData.rows[0].values.ifprop);
                    }*/
                    this.setState({
                        contractPage: 'edit',
                        lastContractPage: 'view'
                    }, () => {
                        this.updateButtonStatus();
                    })
                }
            })
        })
    } else {
        checkBtnPermission(agreeData.rows[0].values.pk_agreement.value, 'edit', 'agreement', () => {
            proFetch({
                url: '/nccloud/hrcm/account/EditContractAction.do',
                body: {
                    pk_org: orgVal.refpk,
                    selectedPk: agreeData.rows[0].values.pk_agreement.value,
                    isContract: false
                },
            }).then((res) => {
                if (res.success) {
                    this.props.form.setFormStatus(agreeArea, 'edit');
                    /*if (agreeData.rows[0].values.hasOwnProperty('ifprop')) {
                        initFormMeta.call(this, 'agree', agreeArea, agreeData.rows[0].values.ifprop);
                    }*/
                    this.setState({
                        agreementPage: 'edit',
                        lastAgreementPage: 'view'
                    }, () => {
                        this.updateButtonStatus();
                    })
                }
            })
        })
    }
}
